package com.service.impl;

import com.mapper.ShopCommentReplyMapper;
import com.pojo.*;
import com.service.ShopCommentReplyService;
import com.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: HL
 * Date: 2020/3/3
 * Time: 14:34
 * Description: No Description
 */
@Service
public class ShopCommentReplyServiceImpl implements ShopCommentReplyService {
    @Autowired
    private ShopCommentReplyMapper shopCommentReplyMapper;

    @Override
    public ServerResponse save(ShopCommentReply shopCommentReply) {
        Byte status =1;
        shopCommentReply.setStatus(status);
        //执行mybatis添加方法
        int rows = shopCommentReplyMapper.insert(shopCommentReply);
        //判断添加成功
        if (rows > 0)
            return ServerResponse.addSuccess();
        else
            return ServerResponse.addFailed();
    }

    @Override
    public ServerResponse modifyStatus(Integer id) {
        ShopCommentReply shopCommentReply = shopCommentReplyMapper.selectByPrimaryKey(id);
        Byte status = 0;
        shopCommentReply.setStatus(status);
        int i = shopCommentReplyMapper.updateByPrimaryKeySelective(shopCommentReply);
        if (i>0)
            return ServerResponse.deleteSuccess();
        return ServerResponse.deleteFailed();
    }

    @Override
    public ServerResponse modify(ShopCommentReply shopCommentReply) {
        int i = shopCommentReplyMapper.updateByPrimaryKeySelective(shopCommentReply);
        if (i>0)
            return ServerResponse.updateSuccess();
        return ServerResponse.updateFailed();
    }

    @Override
    public ServerResponse getById(Integer id) {
        ShopCommentReply shopCommentReply = shopCommentReplyMapper.selectByPrimaryKey(id);
        return ServerResponse.getDataSuccess(shopCommentReply);
    }

    @Override
    public ServerResponse getAll() {
        ShopCommentReplyExample example=new ShopCommentReplyExample();
        ShopCommentReplyExample.Criteria criteria = example.createCriteria();
        Byte status = 1;
        criteria.andStatusEqualTo(status);
        List<ShopCommentReply> shopCommentReplies = shopCommentReplyMapper.selectByExample(example);
        if (shopCommentReplies!=null&&shopCommentReplies.size()>0)
            return ServerResponse.getDataSuccess(shopCommentReplies);
        return ServerResponse.getDataFailed("没有数据");
    }
}
